package MyDisplayObjects 
{
	import flash.events.Event;
	import flash.geom.Point;

	/** This is an example of an object that extends our DraggableMC class.  Basically it is used to draw a simple shape, but retains all the dragging properties
	 * of its parent class, as well as any public methods (functions) or properties (variables).
	 */
	public class DraggableShape extends DraggableMC
	{
		private var oshapeType:String, othickness:Number, olineColor:uint, olineAlpha:Number, ofillColor:uint, ofillAlpha:Number, owidth:Number, oheight:Number=0, oellipseWidth:Number = 0, oellipseHeight:Number = 0, opoints:Array = null;
		/** This will draw a draggable circle, rectangle, round rectangle, or arbitrary shape defined by points.  In the later case, shapeType can be any. 
		 * Otherwise shapeType should be Circle, Rect, RoundRect, Ellipse.  Shape will be registered in top-left corner, for arbitrary shape points will be used as is.
		 * Use the re-register function to minimize the coordines of this arbitrary shape  
		 */ 
		public function DraggableShape(shapeType:String, thickness:Number, lineColor:uint, lineAlpha:Number, fillColor:uint, fillAlpha:Number, width:Number, height:Number=0, ellipseWidth:Number = 0, ellipseHeight:Number = 0, points:Array = null)
		{
			super(); // call this so that if anything important happens in the constructor of the parent class DraggableMC it will occur with this super() function call.
			oshapeType = shapeType; othickness = thickness; olineColor = lineColor, olineAlpha = lineAlpha; ofillColor = fillColor; ofillAlpha = fillAlpha; owidth = width; oheight = height; oellipseWidth = ellipseWidth; oellipseHeight = ellipseHeight; opoints = points;
			if (shapeType.toLowerCase()  == "circle")
			{
				this.graphics.lineStyle(thickness, lineColor, lineAlpha);
				this.graphics.beginFill(fillColor, fillAlpha);
				this.graphics.drawCircle(width/2, width/2, width/2);
				this.graphics.endFill();
			} else if (shapeType.toLowerCase()  == "ellipse")
			{
				this.graphics.lineStyle(thickness, lineColor, lineAlpha);
				this.graphics.beginFill(fillColor, fillAlpha);
				this.graphics.drawEllipse(0, 0, width, height);
				this.graphics.endFill();
			} else if (shapeType.toLowerCase()  == "rect" || shapeType.toLowerCase() == "rectangle")
			{
				this.graphics.lineStyle(thickness, lineColor, lineAlpha);
				this.graphics.beginFill(fillColor, fillAlpha);
				this.graphics.drawRect(0, 0, width, height);
				this.graphics.endFill();
			} else if (shapeType.toLowerCase()  == "roundrect" || shapeType.toLowerCase() == "roundrectangle")
			{
				this.graphics.lineStyle(thickness, lineColor, lineAlpha);
				this.graphics.beginFill(fillColor, fillAlpha);
				this.graphics.drawRoundRect(0, 0, width, height, ellipseWidth, ellipseHeight);
				this.graphics.endFill();
			} else
			{
				if (points != null)
				{
					this.graphics.lineStyle(thickness, lineColor, lineAlpha);
					this.graphics.beginFill(fillColor, fillAlpha);
					// start at last point
					this.graphics.moveTo(points[points.length-1].x, points[points.length-1].y);
					for each (var p:Point in points)
					{
						this.graphics.lineTo(p.x, p.y);
					}
					this.graphics.endFill();
				} else
				{
					trace ("Not an acceptable shape type:", shapeType);
				}
			}
			this.dispatchEvent( new Event(Event.COMPLETE));
		}
		override public function duplicate():DraggableMC
		{
			var dmc:DraggableShape = new DraggableShape(oshapeType, othickness, olineColor, olineAlpha, ofillColor, ofillAlpha, owidth, oheight, oellipseWidth, oellipseHeight, opoints);
			dmc.x = this.x;
			dmc.y = this.y;
			dmc.scaleX = this.scaleX;
			dmc.scaleY = this.scaleY;
			return dmc;
		}
	}
}